home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _81f979b58955cd47348daed5cc830c8e < prev    next >
Encoding:
Text File  |  2002-05-30  |  21.7 KB  |  660 lines

  1. #  Copyright (c) 1990-1994 The Regents of the University of California.
  2. #  Copyright (c) 1994-1996 Sun Microsystems, Inc.
  3. #  See the file "license.terms" for information on usage and redistribution
  4. #  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  5. #
  6. #
  7.  
  8. =head1 NAME
  9.  
  10. Tk::Entry - Create and manipulate Entry widgets 
  11.  
  12. =for category  Tk Widget Classes
  13.  
  14. =head1 SYNOPSIS
  15.  
  16. S<    >I<$entry> = I<$parent>-E<gt>B<Entry>(?I<options>?);
  17.  
  18. =head1 STANDARD OPTIONS
  19.  
  20. B<-background>    B<-highlightbackground>    B<-insertontime>    B<-selectforeground>
  21. B<-borderwidth>    B<-highlightcolor>    B<-insertwidth>    B<-takefocus>
  22. B<-cursor>    B<-highlightthickness>    B<-justify>    B<-textvariable>
  23. B<-exportselection>    B<-insertbackground>    B<-relief>    B<-xscrollcommand>
  24. B<-font>    B<-insertborderwidth>    B<-selectbackground>
  25. B<-foreground>    B<-insertofftime>    B<-selectborderwidth>
  26.  
  27. =head1 WIDGET-SPECIFIC OPTIONS
  28.  
  29. =over 4
  30.  
  31. =item Name:    B<invalidCommand>
  32.  
  33. =item Class:    B<InvalidCommand>
  34.  
  35. =item Switch:    B<-invalidcommand>
  36.  
  37. =item Alias:    B<-invcmd>
  38.  
  39. Specifies a script to eval when B<validateCommand> returns 0.
  40. Setting it to <undef> disables this feature (the default).  The best use
  41. of this option is to set it to I<bell>.  See B<Validation>
  42. below for more information.
  43.  
  44. =item Name:    B<show>
  45.  
  46. =item Class:    B<Show>
  47.  
  48. =item Switch:    B<-show>
  49.  
  50. If this option is specified, then the true contents of the entry
  51. are not displayed in the window.
  52. Instead, each character in the entry's value will be displayed as
  53. the first character in the value of this option, such as ``*''.
  54. This is useful, for example, if the entry is to be used to enter
  55. a password.
  56. If characters in the entry are selected and copied elsewhere, the
  57. information copied will be what is displayed, not the true contents
  58. of the entry.
  59.  
  60. =item Name:    B<state>
  61.  
  62. =item Class:    B<State>
  63.  
  64. =item Switch:    B<-state>
  65.  
  66. Specifies one of two states for the entry:  B<normal> or B<disabled>.
  67. If the entry is disabled then the value may not be changed using widget
  68. methods and no insertion cursor will be displayed, even if the input focus is
  69. in the widget.
  70.  
  71. =item Name:    B<validate>
  72.  
  73. =item Class:    B<Validate>
  74.  
  75. =item Switch:    B<-validate>
  76.  
  77. Specifies the mode in which validation should operate: B<none>,
  78. B<focus>, B<focusin>, B<focusout>, B<key>, or B<all>.
  79. It defaults to B<none>.  When you want validation, you must explicitly
  80. state which mode you wish to use.  See B<Validation> below for more.
  81.  
  82. =item Name:    B<validateCommand>
  83.  
  84. =item Class:    B<ValidateCommand>
  85.  
  86. =item Switch:    B<-validatecommand>
  87.  
  88. =item Alias:    B<-vcmd>
  89.  
  90. Specifies a script to eval when you want to validate the input into
  91. the entry widget.  Setting it to C<undef> disables this feature (the default).
  92. This command must return a valid boolean value.  If it returns 0 (or
  93. the valid boolean equivalent) then it means you reject the new edition
  94. and it will not occur and the B<invalidCommand> will be evaluated if it
  95. is set. If it returns 1, then the new edition occurs.
  96. See B<Validation> below for more information.
  97.  
  98. =item Name:    B<width>
  99.  
  100. =item Class:    B<Width>
  101.  
  102. =item Switch:    B<-width>
  103.  
  104. Specifies an integer value indicating the desired width of the entry window,
  105. in average-size characters of the widget's font.
  106. If the value is less than or equal to zero, the widget picks a
  107. size just large enough to hold its current text.
  108.  
  109. =back
  110.  
  111. =head1 DESCRIPTION
  112.  
  113. The B<Entry> method creates a new window (given by the
  114. $entry argument) and makes it into an entry widget.
  115. Additional options, described above, may be specified on the
  116. command line or in the option database
  117. to configure aspects of the entry such as its colors, font,
  118. and relief.  The B<entry> command returns its
  119. $entry argument.  At the time this command is invoked,
  120. there must not exist a window named $entry, but
  121. $entry's parent must exist.
  122.  
  123. An entry is a widget that displays a one-line text string and
  124. allows that string to be edited using methods described below, which
  125. are typically bound to keystrokes and mouse actions.
  126. When first created, an entry's string is empty.
  127. A portion of the entry may be selected as described below.
  128. If an entry is exporting its selection (see the B<exportSelection>
  129. option), then it will observe the standard X11 protocols for handling the
  130. selection;  entry selections are available as type B<STRING>.
  131. Entries also observe the standard Tk rules for dealing with the
  132. input focus.  When an entry has the input focus it displays an
  133. I<insertion cursor> to indicate where new characters will be
  134. inserted.
  135.  
  136. Entries are capable of displaying strings that are too long to
  137. fit entirely within the widget's window.  In this case, only a
  138. portion of the string will be displayed;  methods described below
  139. may be used to change the view in the window.  Entries use
  140. the standard B<xScrollCommand> mechanism for interacting with
  141. scrollbars (see the description of the B<-xscrollcommand> option
  142. for details).  They also support scanning, as described below.
  143.  
  144. =head1 VALIDATION
  145.  
  146. Validation of entry widgets is derived from part of the patch written by
  147. jhobbs@cs.uoregon.edu.  This works by setting the B<validateCommand>
  148. option to a callback which will be evaluated according to the B<validate>
  149. option as follows:
  150.  
  151. =over 4
  152.  
  153. =item B<none>
  154.  
  155. Default.  This means no validation will occur.
  156.  
  157. =item B<focus>
  158.  
  159. B<validateCommand> will be called when the entry receives or
  160. loses focus.
  161.  
  162. =item B<focusin>
  163.  
  164. B<validateCommand> will be called when the entry receives focus.
  165.  
  166. =item B<focusout>
  167.  
  168. B<validateCommand> will be called when the entry loses focus.
  169.  
  170. =item B<key>
  171.  
  172. B<validateCommand> will be called when the entry is edited.
  173.  
  174. =item B<all>
  175.  
  176. B<validateCommand> will be called for all above conditions.
  177.  
  178. =back 
  179.  
  180. The B<validateCommand> and B<invalidCommand> are called with the following 
  181. arguments:
  182.  
  183. =over 4
  184.  
  185. =item * The proposed value of the entry.  If you are configuring the
  186. entry widget to have a new textvariable, this will be the value of that
  187. textvariable.
  188.  
  189. =item * The characters to be added (or deleted). This will be C<undef>
  190. if validation is due to focus, explcit call to validate or if change
  191. is due to C<-textvariable> changing.
  192.  
  193. =item * The current value of entry i.e. before the proposed change.
  194.  
  195. =item * index of char string to be added/deleted, if any. -1 otherwise
  196.  
  197. =item * type of action. 1 == INSERT, 0 == DELETE,
  198. -1 if it's a forced validation or textvariable validation
  199.  
  200. =back 
  201.  
  202. In general, the B<textVariable> and B<validateCommand> can be
  203. dangerous to mix. If you try set the B<textVariable>
  204. to something that the B<validateCommand> will not accept it will 
  205. be set back to the value of the entry widget.  
  206. Using the B<textVariable> for read-only purposes will never cause problems.
  207.  
  208. The B<validateCommand> will turn itself off by setting
  209. B<validate> to B<none> when an error occurs, for example
  210. when the B<validateCommand> or B<invalidCommand> encounters 
  211. an error in its script while evaluating, or
  212. B<validateCommand> does not return a valid boolean value.  
  213.  
  214. With the perl/Tk version B<validate> option is supposed to be 
  215. "suspended" while executing the B<validateCommand> or the B<invalidCommand>. 
  216. This is experimental but in theory either callback can "correct" the 
  217. value of the widget, and override the proposed change. (B<validateCommand>
  218. should still return false to inhibit the change from happening when 
  219. it returns.)
  220.  
  221. =head1 WIDGET METHODS
  222.  
  223. The B<Entry> method creates a widget object.
  224. This object supports the B<configure> and B<cget> methods
  225. described in L<Tk::options> which can be used to enquire and
  226. modify the options described above.
  227. The widget also inherits all the methods provided by the generic
  228. L<Tk::Widget|Tk::Widget> class.
  229.  
  230. Many of the additional methods for entries take one or more indices as
  231. arguments.  An index specifies a particular character in the entry's
  232. string, in any of the following ways:
  233.  
  234. =over 4
  235.  
  236. =item I<number>
  237.  
  238. Specifies the character as a numerical index, where 0 corresponds
  239. to the first character in the string.
  240.  
  241. =item B<anchor>
  242.  
  243. Indicates the anchor point for the selection, which is set with the
  244. B<selectionFrom> and B<selectionAdjust> methods.
  245.  
  246. =item B<end>
  247.  
  248. Indicates the character just after the last one in the entry's string.
  249. This is equivalent to specifying a numerical index equal to the length
  250. of the entry's string.
  251.  
  252. =item B<insert>
  253.  
  254. Indicates the character adjacent to and immediately following the
  255. insertion cursor.
  256.  
  257. =item B<sel.first>
  258.  
  259. Indicates the first character in the selection.  It is an error to
  260. use this form if the selection isn't in the entry window.
  261.  
  262. =item B<sel.last>
  263.  
  264. Indicates the character just after the last one in the selection.
  265. It is an error to use this form if the selection isn't in the
  266. entry window.
  267.  
  268. =item B<@>I<number>
  269.  
  270. In this form, I<number> is treated as an x-coordinate in the
  271. entry's window;  the character spanning that x-coordinate is used.
  272. For example, ``B<@0>'' indicates the left-most character in the
  273. window.
  274.  
  275. =back
  276.  
  277. Abbreviations may be used for any of the forms above, e.g. ``B<e>''
  278. or ``B<sel.f>''.  In general, out-of-range indices are automatically
  279. rounded to the nearest legal value.
  280.  
  281. The following additional methods are available for entry widgets:
  282.  
  283. =over 4
  284.  
  285. =item I<$entry>-E<gt>B<bbox>(I<index>)
  286.  
  287. Returns a list of four numbers describing the bounding box of the
  288. character given by I<index>.
  289. The first two elements of the list give the x and y coordinates of
  290. the upper-left corner of the screen area covered by the character
  291. (in pixels relative to the widget) and the last two elements give
  292. the width and height of the character, in pixels.
  293. The bounding box may refer to a region outside the visible area
  294. of the window.
  295.  
  296. =item I<$entry>-E<gt>B<delete>(I<first, >?I<last>?)
  297.  
  298. Returns the current value of the configuration option given
  299. by I<option>.
  300. I<Option> may have any of the values accepted by the B<entry>
  301. command.
  302.  
  303. =item I<$entry>-E<gt>B<configure>(?I<option>?, ?I<value, option, value, ...>?)
  304.  
  305. Query or modify the configuration options of the widget.
  306. If no I<option> is specified, returns a list describing all of
  307. the available options for $entry (see L<Tk::configure> for
  308. information on the format of this list).  If I<option> is specified
  309. with no I<value>, then the command returns a list describing the
  310. one named option (this list will be identical to the corresponding
  311. sublist of the value returned if no I<option> is specified).  If
  312. one or more I<option-value> pairs are specified, then the command
  313. modifies the given widget option(s) to have the given value(s);  in
  314. this case the command returns an empty string.
  315. I<Option> may have any of the values accepted by the B<entry>
  316. command.
  317.  
  318. =item I<$entry>-E<gt>B<delete>(I<first, >?I<last>?)
  319.  
  320. Delete one or more elements of the entry.
  321. I<First> is the index of the first character to delete, and
  322. I<last> is the index of the character just after the last
  323. one to delete.
  324. If I<last> isn't specified it defaults to I<first>+1,
  325. i.e. a single character is deleted.
  326. This method returns an empty string.
  327.  
  328. =item I<$entry>-E<gt>B<get>
  329.  
  330. Returns the entry's string.
  331.  
  332. =item I<$entry>-E<gt>B<icursor>(I<index>)
  333.  
  334. Arrange for the insertion cursor to be displayed just before the character
  335. given by I<index>.  Returns an empty string.
  336.  
  337. =item I<$entry>-E<gt>B<index>(I<index>)
  338.  
  339. Returns the numerical index corresponding to I<index>.
  340.  
  341. =item I<$entry>-E<gt>B<insert>(I<index, string>)
  342.  
  343. Insert the characters of I<string> just before the character
  344. indicated by I<index>.  Returns an empty string.
  345.  
  346. =item I<$entry>->B<scan>(I<option, args>)
  347.  
  348. =item I<$entry>->B<scan>I<Option>(I<args>)
  349.  
  350. This method is used to implement scanning on entries.  It has
  351. two forms, depending on I<Option>:
  352.  
  353. =over 8
  354.  
  355. =item I<$entry>->B<scanMark>(I<x>)
  356.  
  357. Records I<x> and the current view in the entry widget;  used in
  358. conjunction with later B<scanDragto> methods.  Typically this
  359. method is associated with a mouse button press in the widget.  It
  360. returns an empty string.
  361.  
  362. =item I<$entry>->B<scanDragto>(I<x>)
  363.  
  364. This method computes the difference between its I<x> argument
  365. and the I<x> argument to the last B<scanMark> method for
  366. the widget.  It then adjusts the view left or right by 10 times the
  367. difference in x-coordinates.  This method is typically associated
  368. with mouse motion events in the widget, to produce the effect of
  369. dragging the entry at high speed through the widget.  The return
  370. value is an empty string.
  371.  
  372. =back
  373.  
  374. =item I<$entry>->B<selection>(I<option, arg>)
  375.  
  376. =item I<$entry>->B<selection>I<Option>(I<arg>)
  377.  
  378. This method is used to adjust the selection within an entry.  It
  379. has several forms, depending on I<Option>:
  380.  
  381. =over 8
  382.  
  383. =item I<$entry>-E<gt>B<selectionAdjust>(I<index>)
  384.  
  385. Locate the end of the selection nearest to the character given by
  386. I<index>, and adjust that end of the selection to be at I<index>
  387. (i.e including but not going beyond I<index>).  The other
  388. end of the selection is made the anchor point for future
  389. B<selectionTo> methods.  If the selection
  390. isn't currently in the entry, then a new selection is created to
  391. include the characters between I<index> and the most recent
  392. selection anchor point, inclusive.
  393. Returns an empty string.
  394.  
  395. =item I<$entry>-E<gt>B<selectionClear>
  396.  
  397. Clear the selection if it is currently in this widget.  If the
  398. selection isn't in this widget then the method has no effect.
  399. Returns an empty string.
  400.  
  401. =item I<$entry>-E<gt>B<selectionFrom>(I<index>)
  402.  
  403. Set the selection anchor point to just before the character
  404. given by I<index>.  Doesn't change the selection.
  405. Returns an empty string.
  406.  
  407. =item I<$entry>-E<gt>B<selectionPresent>
  408.  
  409. Returns 1 if there is are characters selected in the entry,
  410. 0 if nothing is selected.
  411.  
  412. =item I<$entry>-E<gt>B<selectionRange>(I<start, >I<end>)
  413.  
  414. Sets the selection to include the characters starting with
  415. the one indexed by I<start> and ending with the one just
  416. before I<end>.
  417. If I<end> refers to the same character as I<start> or an
  418. earlier one, then the entry's selection is cleared.
  419.  
  420. =item I<$entry>-E<gt>B<selectionTo>(I<index>)
  421.  
  422. If I<index> is before the anchor point, set the selection
  423. to the characters from I<index> up to but not including
  424. the anchor point.
  425. If I<index> is the same as the anchor point, do nothing.
  426. If I<index> is after the anchor point, set the selection
  427. to the characters from the anchor point up to but not including
  428. I<index>.
  429. The anchor point is determined by the most recent B<selectionFrom>
  430. or B<selectionAdjust> method in this widget.
  431. If the selection isn't in this widget then a new selection is
  432. created using the most recent anchor point specified for the widget.
  433. Returns an empty string.
  434.  
  435. =back
  436.  
  437. =item I<$entry>-E<gt>B<validate>
  438.  
  439. This command is used to force an evaluation of the B<validateCommand>
  440. independent of the conditions specified by the B<validate> option.  It
  441. returns 0 or 1.
  442.  
  443. =item I<$entry>-E<gt>B<xview>(I<args>)
  444.  
  445. This command is used to query and change the horizontal position of the
  446. text in the widget's window.  It can take any of the following
  447. forms:
  448.  
  449. =over 8
  450.  
  451. =item I<$entry>-E<gt>B<xview>
  452.  
  453. Returns a list containing two elements.
  454. Each element is a real fraction between 0 and 1;  together they describe
  455. the horizontal span that is visible in the window.
  456. For example, if the first element is .2 and the second element is .7,
  457. 20% of the entry's text is off-screen to the left, the middle 50% is visible
  458. in the window, and 30% of the text is off-screen to the right.
  459. These are the same values passed to scrollbars via the B<-xscrollcommand>
  460. option.
  461.  
  462. =item I<$entry>-E<gt>B<xview>(I<index>)
  463.  
  464. Adjusts the view in the window so that the character given by I<index>
  465. is displayed at the left edge of the window.
  466.  
  467. =item I<$entry>-E<gt>B<xviewMoveto>(I<fraction>)
  468.  
  469. Adjusts the view in the window so that the character I<fraction> of the
  470. way through the text appears at the left edge of the window.
  471. I<Fraction> must be a fraction between 0 and 1.
  472.  
  473. =item I<$entry>-E<gt>B<xviewScroll>(I<number, what>)
  474.  
  475. This method shifts the view in the window left or right according to
  476. I<number> and I<what>.
  477. I<Number> must be an integer.
  478. I<What> must be either B<units> or B<pages> or an abbreviation
  479. of one of these.
  480. If I<what> is B<units>, the view adjusts left or right by
  481. I<number> average-width characters on the display;  if it is
  482. B<pages> then the view adjusts by I<number> screenfuls.
  483. If I<number> is negative then characters farther to the left
  484. become visible;  if it is positive then characters farther to the right
  485. become visible.
  486.  
  487. =back
  488.  
  489. =head1 DEFAULT BINDINGS
  490.  
  491. Tk automatically creates class bindings for entries that give them
  492. the following default behavior.
  493. In the descriptions below, ``word'' refers to a contiguous group
  494. of letters, digits, or ``_'' characters, or any single character
  495. other than these.
  496.  
  497. =over 4
  498.  
  499. =item [1]
  500.  
  501. Clicking mouse button 1 positions the insertion cursor
  502. just before the character underneath the mouse cursor, sets the
  503. input focus to this widget, and clears any selection in the widget.
  504. Dragging with mouse button 1 strokes out a selection between
  505. the insertion cursor and the character under the mouse.
  506.  
  507. =item [2]
  508.  
  509. Double-clicking with mouse button 1 selects the word under the mouse
  510. and positions the insertion cursor at the beginning of the word.
  511. Dragging after a double click will stroke out a selection consisting
  512. of whole words.
  513.  
  514. =item [3]
  515.  
  516. Triple-clicking with mouse button 1 selects all of the text in the
  517. entry and positions the insertion cursor before the first character.
  518.  
  519. =item [4]
  520.  
  521. The ends of the selection can be adjusted by dragging with mouse
  522. button 1 while the Shift key is down;  this will adjust the end
  523. of the selection that was nearest to the mouse cursor when button
  524. 1 was pressed.
  525. If the button is double-clicked before dragging then the selection
  526. will be adjusted in units of whole words.
  527.  
  528. =item [5]
  529.  
  530. Clicking mouse button 1 with the Control key down will position the
  531. insertion cursor in the entry without affecting the selection.
  532.  
  533. =item [6]
  534.  
  535. If any normal printing characters are typed in an entry, they are
  536. inserted at the point of the insertion cursor.
  537.  
  538. =item [7]
  539.  
  540. The view in the entry can be adjusted by dragging with mouse button 2.
  541. If mouse button 2 is clicked without moving the mouse, the selection
  542. is copied into the entry at the position of the mouse cursor.
  543.  
  544. =item [8]
  545.  
  546. If the mouse is dragged out of the entry on the left or right sides
  547. while button 1 is pressed, the entry will automatically scroll to
  548. make more text visible (if there is more text off-screen on the side
  549. where the mouse left the window).
  550.  
  551. =item [9]
  552.  
  553. The Left and Right keys move the insertion cursor one character to the
  554. left or right;  they also clear any selection in the entry and set
  555. the selection anchor.
  556. If Left or Right is typed with the Shift key down, then the insertion
  557. cursor moves and the selection is extended to include the new character.
  558. Control-Left and Control-Right move the insertion cursor by words, and
  559. Control-Shift-Left and Control-Shift-Right move the insertion cursor
  560. by words and also extend the selection.
  561. Control-b and Control-f behave the same as Left and Right, respectively.
  562. Meta-b and Meta-f behave the same as Control-Left and Control-Right,
  563. respectively.
  564.  
  565. =item [10]
  566.  
  567. The Home key, or Control-a, will move the insertion cursor to the
  568. beginning of the entry and clear any selection in the entry.
  569. Shift-Home moves the insertion cursor to the beginning of the entry
  570. and also extends the selection to that point.
  571.  
  572. =item [11]
  573.  
  574. The End key, or Control-e, will move the insertion cursor to the
  575. end of the entry and clear any selection in the entry.
  576. Shift-End moves the cursor to the end and extends the selection
  577. to that point.
  578.  
  579. =item [12]
  580.  
  581. The Select key and Control-Space set the selection anchor to the position
  582. of the insertion cursor.  They don't affect the current selection.
  583. Shift-Select and Control-Shift-Space adjust the selection to the
  584. current position of the insertion cursor, selecting from the anchor
  585. to the insertion cursor if there was not any selection previously.
  586.  
  587. =item [13]
  588.  
  589. Control-/ selects all the text in the entry.
  590.  
  591. =item [14]
  592.  
  593. Control-\ clears any selection in the entry.
  594.  
  595. =item [15]
  596.  
  597. The F16 key (labelled Copy on many Sun workstations) or Meta-w
  598. copies the selection in the widget to the clipboard, if there is a selection.
  599.  
  600. =item [16]
  601.  
  602. The F20 key (labelled Cut on many Sun workstations) or Control-w
  603. copies the selection in the widget to the clipboard and deletes
  604. the selection.
  605. If there is no selection in the widget then these keys have no effect.
  606.  
  607. =item [17]
  608.  
  609. The F18 key (labelled Paste on many Sun workstations) or Control-y
  610. inserts the contents of the clipboard at the position of the
  611. insertion cursor.
  612.  
  613. =item [18]
  614.  
  615. The Delete key deletes the selection, if there is one in the entry.
  616. If there is no selection, it deletes the character to the right of
  617. the insertion cursor.
  618.  
  619. =item [19]
  620.  
  621. The BackSpace key and Control-h delete the selection, if there is one
  622. in the entry.
  623. If there is no selection, it deletes the character to the left of
  624. the insertion cursor.
  625.  
  626. =item [20]
  627.  
  628. Control-d deletes the character to the right of the insertion cursor.
  629.  
  630. =item [21]
  631.  
  632. Meta-d deletes the word to the right of the insertion cursor.
  633.  
  634. =item [22]
  635.  
  636. Control-k deletes all the characters to the right of the insertion
  637. cursor.
  638.  
  639. =item [23]
  640.  
  641. Control-t reverses the order of the two characters to the right of
  642. the insertion cursor.
  643.  
  644. If the entry is disabled using the B<-state> option, then the entry's
  645. view can still be adjusted and text in the entry can still be selected,
  646. but no insertion cursor will be displayed and no text modifications will
  647. take place.
  648.  
  649. The behavior of entries can be changed by defining new bindings for
  650. individual widgets or by redefining the class bindings.
  651.  
  652. =back
  653.  
  654. =head1 KEYWORDS
  655.  
  656. entry, widget
  657.  
  658. =cut
  659.  
  660.